package com.boang.web;

import com.boang.po.Student;
import com.boang.service.StudentServiceImpl;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
import java.util.List;

/*
  @author: 13813
  @date: 2024/7/12 15:58
*/
@WebServlet("/h05")
public class ServletDemo05 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        HttpSession session = req.getSession();
//        String useranme = (String) session.getAttribute("abc");
//        if (useranme != null || !useranme.equals("")) {
            //创建service对象
            StudentServiceImpl studentService = new StudentServiceImpl();
            //调用service类中查询全部学生的方法
            List<Student> studentList = studentService.getStuAll();
            req.setAttribute("stus", studentList);

            RequestDispatcher dispatcher = req.getRequestDispatcher("stu.jsp");
            dispatcher.forward(req, resp);
//        } else {
//            resp.sendRedirect("index.jsp");
//        }
    }
}
